import org.junit.Test;
import org.tool.net.HttpClient;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * RabbitMQ测试类
 *
 * @author 李坤
 * @date 2022/9/1 11:17
 */
public class RabbitMq {

    private final Executor executor = Executors.newFixedThreadPool(12);

    @Test
    public void sendMessage() throws InterruptedException {
        final CountDownLatch countDownLatch = new CountDownLatch(10);

        for (int i = 0; i < 10; i++) {
            CompletableFuture.runAsync(() -> {
                try {
                    HttpClient.get("http://localhost:8080/rabbit/direct");
                } catch (IOException exception) {
                    exception.printStackTrace();
                } finally {
                    countDownLatch.countDown();
                    try {
                        countDownLatch.await();
                    } catch (InterruptedException exception) {
                        exception.printStackTrace();
                    }
                }
            }, executor);
        }
        countDownLatch.await();
    }

}
